package cn.liangent.travlib;

public class Coordinate {
	private int x, y, d;

	public Coordinate(int d) {
		if (d < 1 || d > 641601) {
			throw new IllegalArgumentException("d < 1 || d > 641601");
		}
		this.d = d;
		// copied from MR's code
		x = (d - 401) % 801;
		y = 400 - (d - 401) / 801;
	}

	public Coordinate(int x, int y) {
		if (x < -400 || x > 400) {
			throw new IllegalArgumentException("x < -400 || x > 400");
		}
		if (y < -400 || y > 400) {
			throw new IllegalArgumentException("y < -400 || y > 400");
		}
		this.x = x;
		this.y = y;
		// copied from MR's code
		d = 801 * (400 - y) + x + 401;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public int getD() {
		return d;
	}
}
